package io.github.i678.bukkitantipmc;

import io.github.i678.bukkitantipmc.utils.ChatUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.logging.Level;

public class Command extends AntiFakePMC implements CommandExecutor {

    /**
     * AntiFakePMC plugin command.
     * @param sender - The command sender
     * @param cmd - The command
     * @param label - The string command label
     * @param args - The arguments
     * @return true - all the time.
     */
    @Override
    public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) {
        if(sender instanceof Player) {
            Player player = (Player) sender;
            if(args.length == 0) {
                ChatUtils.help(player);
            } else if(args[0].equalsIgnoreCase("dev")) {
                if(sender.hasPermission("antipmc.use.toggle.dev")) {
                    if(dev) {
                        dev = false;
                        sender.sendMessage(messageNormal + "Dev mode: " + ChatColor.RED + "OFF");
                    } else {
                        dev = true;
                        sender.sendMessage(messageNormal + "Dev mode: " + ChatColor.GREEN + "ON");
                    }
                } else {
                    sender.sendMessage(messageNormal + "Not enough permissions.");
                }
            } else if(args[0].equalsIgnoreCase("help")) {
                if(args.length == 1) {
                    ChatUtils.help(player);
                } else if(args[1].equalsIgnoreCase("dev")) {
                    sender.sendMessage(ChatColor.GREEN + "Usage: " + ChatColor.LIGHT_PURPLE + "/antipmc dev <on|off>");
                    sender.sendMessage(ChatColor.GREEN + "Enables / disables DEV mode. Useful if the AntiFakePMC dev is coming over to help with an issue with the plugin.");
                } else if(args[1].equalsIgnoreCase("help")) {
                    sender.sendMessage(ChatColor.GREEN + "Usage: " + ChatColor.LIGHT_PURPLE + "/antipmc help [command]");
                    sender.sendMessage(ChatColor.GREEN + "This should be obvious. But, for those who want an actual explanation.. It shows all the AntiPMC commands, or a certain command.");
                } else if(args[1].equalsIgnoreCase("notice")) {
                    sender.sendMessage(ChatColor.GREEN + "Usage: " + ChatColor.LIGHT_PURPLE + "/antipmc notify <global|permissions|console|off>");
                    sender.sendMessage(ChatColor.GREEN + "Allows the player with this command to modify the Notifiy option in game. If there is no option to change it, it prints out the current setting.");
                    sender.sendMessage(ChatColor.GREEN + "Permission: " + ChatColor.BLUE + "antipmc.use.modify.notify");
                } else if(args[1].equalsIgnoreCase("depend")) {
                    sender.sendMessage(ChatColor.GREEN + "Usage:" + ChatColor.LIGHT_PURPLE + " /antipmc depend [depend name] [enable|disable]");
                    sender.sendMessage(ChatColor.GREEN + "Prints out the supported addons with the plugin. If the config for 'forcePluginCheck' is true, it forcefully checks again before printing out the plugins.");
                    sender.sendMessage(ChatColor.GREEN + "Permission: " + ChatColor.BLUE + "antipmc.use.depend");
                } else if(args[1].equalsIgnoreCase("version") || args[1].equalsIgnoreCase("v")) {
                    sender.sendMessage(ChatColor.GREEN + "Usage:" + ChatColor.LIGHT_PURPLE + " /antipmc version");
                    sender.sendMessage(ChatColor.GREEN + "This should be obvious. Prints out plugin version and Bukkit version.");
                    sender.sendMessage(ChatColor.GREEN + "Permission: " + ChatColor.BLUE + "antipmc.use.version");
                } else {
                    ChatUtils.help(player);
                }
            } else if(args[0].equalsIgnoreCase("notify")) {
                if(sender.hasPermission("antipmc.use.modify.notify")) {
                    if(args.length == 1) {
                        sender.sendMessage(messageNormal + "Not enough arguments.");
                        sender.sendMessage(messageNormal + "Usage: /antipmc notify <global|permissions|console|off>");
                        sender.sendMessage(messageNormal + "Current setting: " + ChatColor.LIGHT_PURPLE + notify);
                        return false;
                    }
                    if(args[1].equalsIgnoreCase("permissions")) {
                        notify = "permissions";
                        sender.sendMessage(messageNormal + "Notify setting changed to: " + ChatColor.LIGHT_PURPLE + notify);
                    } else if(args[1].equalsIgnoreCase("global")) {
                        notify = "global";
                        sender.sendMessage(messageNormal + "Notify setting changed to: " + ChatColor.LIGHT_PURPLE + notify);
                    } else if(args[1].equalsIgnoreCase("console")) {
                        notify = "console";
                        sender.sendMessage(messageNormal + "Notify setting changed to: " + ChatColor.LIGHT_PURPLE + notify);
                    } else if(args[1].equalsIgnoreCase("off")) {
                        notify = "off";
                        sender.sendMessage(messageNormal + "Notify setting changed to: " + ChatColor.LIGHT_PURPLE + notify);
                    } else {
                        sender.sendMessage(messageNormal + "Unknown notify type '" + args[1] + "'.");
                        sender.sendMessage(messageNormal + "Usage: /antipmc notify <global|permissions|console|off>");
                    }
                } else {
                    sender.sendMessage(messageNormal + "Not enough permissions.");
                }
            }

            else {
                sender.sendMessage(messageNormal + "Unknown command. Do '/antipmc help' to see the AntiFakePMC commands you can access.");
            }
        } else {
            //ChatUtils.logMessage(Level.INFO, "You can do this command via your Minecraft client. There is no reason to do it from the console.");
            ChatUtils.logMessage(Level.INFO, "Here are the settings for the AntiFakePMC plugin.");
            ChatUtils.logMessage(Level.INFO, "Notify type: " + notify);
            ChatUtils.logMessage(Level.INFO, "Dev mode: " + dev);
            ChatUtils.logMessage(Level.INFO, "Debug mode: " + debug);
            ChatUtils.logMessage(Level.INFO, "Severe filters: " + severe);
            ChatUtils.logMessage(Level.INFO, "Version: " + version);
        }
        return true;
    }


}
